package io.github.uicdb.liba.api.register.data;

import com.google.common.collect.Multimap;
import io.github.uicdb.liba.api.register.BlockHolder;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.tags.BlockTagsProvider;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;

public class LazyBlockTagProvider extends BlockTagsProvider {
    private final Multimap<BlockHolder<?>, TagKey<Block>> map;
    HashMap<TagKey<Block>, TagKey<Block>> blockCopyMap;
    public LazyBlockTagProvider(DataGenerator pGenerator, String modId, @Nullable ExistingFileHelper existingFileHelper, Multimap<BlockHolder<?>, TagKey<Block>> map, HashMap<TagKey<Block>, TagKey<Block>> blockCopyMap) {
        super(pGenerator, modId, existingFileHelper);
        this.map = map;
        this.blockCopyMap=blockCopyMap;
    }

    @Override
    protected void addTags() {
        map.forEach((blockHolder, tagKey) -> LazyBlockTagProvider.this.tag(tagKey).add(blockHolder.get()));
        blockCopyMap.forEach((from,to)->LazyBlockTagProvider.this.tag(to).addTag(from));
    }

    @NotNull
    @Override
    public String getName() {
        return "LazyBlockTagProvider For " + modId;
    }
}
